package edu.ptit.jad.preprocess.analysis;



import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.LetterTokenizer;
import org.apache.lucene.analysis.LowerCaseFilter;
import org.apache.lucene.analysis.StopFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.analysis.WhitespaceTokenizer;
import org.apache.lucene.analysis.standard.StandardTokenizer;
import org.apache.lucene.analysis.standard.StandardFilter;
import org.apache.lucene.util.Version;

import edu.ptit.jad.exception.AdException;

import java.io.Reader;


public class SynonymAnalyzer extends Analyzer {
	private SynonymEngine engine;

	public SynonymAnalyzer(SynonymEngine engine) {
		this.engine = engine;
	}

	public SynonymAnalyzer() {
		this.engine = new VietnameseSynonymEngine();
	}

	public TokenStream tokenStream(String fieldName, Reader reader) {
		TokenStream result = null;
		try {
			result = new SynonymFilter(new StopFilter(true,
					new LowerCaseFilter(new StandardFilter(new WhitespaceTokenizer(
							Version.LUCENE_30, reader))),
					VietnameseStopWords.getStopWords()), engine);
		} catch (AdException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

}
